/**
 * 供应商信息编辑controller.
 * @author 马玉德
 * @version 1.0.0, 2015-12-07
 */
Ext.define('MyApp.controller.EditCtrl', {
		extend: 'Ext.app.Controller',
		views: [
			'EditView'
		],
		init: function () {
			//调用父类方法
			this.callParent();
			this.control({
				//保存按钮事件
				'editview  button[name=btn-save]': {
					click: this.onSave
				},
				//窗体事件
				//'editview button[name=btn_img]': {
				//	//视图显示事件
				//	click: this.import_excel
				//}
				//上传按钮事件
				'editview  button[name=btn-up]': {
					click: this.onUp
				},
			});
		},
		/**
		 * 视图显示事件
		 */
		onShow: function (view, eOpts) {
			//刷新供应商性质下拉框数据
			view.down('combobox[name=supplierNature]').getStore().reload();
		},
		//保存按钮事件
		onSave: function (button) {
			var win = button.up('window');
			console.log(win.down('ckeditor').getValue());
			//console.log("run");
			//var win = button.up('window');
			////取得表单对象
			//var form = win.down('form');
			////验证表单
			////if(!form.isValid()){//表单有错误
			////	ACBEE.Ext.Util.showAlertBox("表单有错误，请修改后再保存！");
			////	return false;
			////}
            //
			////var oldSupplierId = win.oldSupplierId;
			////提交表单内容到后台
			//var formValues = form.getForm().getValues();
            //
			//WX.Ext.Util.submitFormData(form, 'user/save.action', {datas: Ext.encode(formValues)},
			//	"路线信息保存成功", "路线信息保存失败！！！", function () {
			//		if (undefined != win.parentStore) {
			//			//刷新父窗体表格
			//			win.parentStore.reload();
			//		}
			//		win.close();
			//	});
		},

		import_excel: function (button) {
			//v = new fileuploadwd();
			//v.show();
			WX.Ext.Util.loadController(this.application, "MyApp.controller.FileCtrl");
			//取得供应商window
			var win = WX.Ext.Util.getWin('fileupload');
			win.show();
		},

		//上传按钮事件
		onUp: function(button) {
			console.log("run");
			var win = button.up('window');
			//取得表单对象
			var panel = win.down('panel');
			var form = win.down('form');
			if (form.isValid()) {
				form.submit({
					url: '/MyProject/file/import_img.action',
					//waitMsg : '正在上传',
					success: function (fp, action) {
						Ext.getCmp("imagebox").getEl().dom.src = action.result.path;
					}
				});
			}
		},
	}
);